package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.cucc.common.util.DateFormatUtils;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.base.util.LocalAttrUtils;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @Classname RequiredDateAttrHandler
 * @Description 时间类型字段，默认当前时间+n天
 * @Author zhang.song
 * @Date 2021-02-23 10:01
 */
public class RequiredDateJPWAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {


    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Override
    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {

    /*    String nodeCode = querySceneInstService.getExtParameterValue(data.getSceneInstId(), "nodeCode");
        // 核查
        String value = attr.getValue();
        if(KiteStringUtils.isEmpty(attr.getDefaultValue())){
            if(data.getServiceOfferId().equals(LocalServiceOfferConsts.SERVICE_OFFER_RESOURCE_CHECK)){
                //核查重提
                String productId = inst.getSpecId();
                if("OrderResubmit".equals(nodeCode)){
                    value = LocalAttrUtils.compareDate(attr, inst.getSpecId(),null);
                    attr.setDefaultValue(value);
                }else{
                    value = LocalAttrUtils.getInstance().AZOffsetDay(productId ,null,null);
                    attr.setDefaultValue(value);
                }
            }
            attr.setValue(value);
            //        核查追单追单校验
            if (KiteStringUtils.equals(data.getServiceOfferId(), LocalServiceOfferConsts.SERVICE_OFFER_FOLLOW)&&"OrderResourceCheck".equals(nodeCode)) {
                attr.setValue(LocalAttrUtils.compareDate(attr, inst.getSpecId(),null));
                attr.setDefaultValue(LocalAttrUtils.compareDate(attr, inst.getSpecId(),null));
            }
        }
        // 订单补录情况，来单属性为空时，不设置默认值，否则会有展示属性值与甩单填写不一致情况
        if(KiteStringUtils.isEmpty(value)&&!KiteStringUtils.isEmpty(attr.getDefaultValue())){
            attr.setValue(attr.getDefaultValue());
            attr.setValueDesc(attr.getDefaultValue());
        }
        super.onShow(attr,inst,data);
        IOperateSceneInstService operateSceneInstService = SpringUtil.getBean(IOperateSceneInstService.class);
        operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), attr);*/

    }
    @Override
    public void before(KiteAttr attr, KiteInst inst,  String value,AttrData data) {
      /*  if(data.getServiceOfferId().equals(LocalServiceOfferConsts.SERVICE_OFFER_RESOURCE_CHECK)){
            //核查重提
            if(attr!=null&&KiteStringUtils.isNotEmpty(attr.getDefaultValue())&& DateFormatUtils.compareDate(value,attr.getDefaultValue() , DateFormatUtils.DATE_MINUTE_FORMAT) < 0){
                ErrorConsts.BUSI_COMMON_ERROR.throwOut("可选择的日期不能早于初始化的日期:"+attr.getDefaultValue());
            }
        }
        //        核查追单追单校验

        if (KiteStringUtils.equals(data.getServiceOfferId(), LocalServiceOfferConsts.SERVICE_OFFER_FOLLOW)) {
            Map<String, Object> extParams = ContextUtil.getLoginInfo().getUserInfo().getExtParams();
            if("OrderResourceCheck".equals(extParams.get("nodeCode"))){
                if(attr!=null&&KiteStringUtils.isNotEmpty(attr.getDefaultValue())&&DateFormatUtils.compareDate(value,attr.getDefaultValue() , DateFormatUtils.DATE_MINUTE_FORMAT) < 0){
                    ErrorConsts.BUSI_COMMON_ERROR.throwOut("可选择的日期不能早于初始化的日期:"+attr.getDefaultValue());
                }
            }
        }*/

    }
}
